Skip to content

fix(cli): resume selected session in cn ls instead of the latest#12974

Open
Purv-Kabaria wants to merge 2 commits into
continuedev:mainfrom
Purv-Kabaria:12927-fix-cn-ls-resume-selected-session
Open

fix(cli): resume selected session in cn ls instead of the latest#12974
Purv-Kabaria wants to merge 2 commits into
continuedev:mainfrom
Purv-Kabaria:12927-fix-cn-ls-resume-selected-session

Conversation

@Purv-Kabaria

@Purv-Kabaria Purv-Kabaria commented Jul 10, 2026

Copy link
Copy Markdown

Description

Fixes #12927.

cn ls lets you pick a past session from the TUI, but resuming always reopened the most recent session regardless of which one you selected.

Root cause is in extensions/cli/src/session.ts. loadSession() sorts the session files by mtime and unconditionally loads files[0]:

// Load the most recent session
const session: Session = JSON.parse(fs.readFileSync(files[0].path, "utf8"));

The cn ls flow (commands/ls.ts) already communicates the chosen session by setting CONTINUE_CLI_TEST_SESSION_ID — the same env var SessionManager.getCurrentSession() uses to pin the current session id — before calling chat({ resume: true }). But loadSession() never read that var, so the selection was silently dropped and --resume always fell back to the latest session.

This PR makes loadSession() honor CONTINUE_CLI_TEST_SESSION_ID first (loading that session by id via the existing loadSessionById()), falling back to the most-recent session when the var is absent or the id can't be loaded. Plain cn --resume is unchanged.

The fix is intentionally minimal — one guard at the top of loadSession(), no signature or caller changes.

Note: the env var name (CONTINUE_CLI_TEST_SESSION_ID) reads as test-only, but it is already used on the production cn ls path today. I kept the existing name to stay minimal; happy to rename it in a follow-up if maintainers prefer a non-TEST name for this now-user-facing mechanism.

Checklist

  • I've read the contributing guide
  • The relevant docs, if any, have been updated or created (no user-facing docs affected)
  • The relevant tests, if any, have been updated or created

Tests

Added a unit test in extensions/cli/src/session.test.ts under loadSession:

  • should load the selected session when CONTINUE_CLI_TEST_SESSION_ID is set — sets the env var and asserts loadSession() resolves the session by id (historyManager.load called with the selected id), does not fall back to scanning the directory by mtime (readdirSync not called), and sets it as the current session.

I verified the test fails on main (without the fix) and passes with it. Existing loadSession tests (including "should load the most recent session" for the no-selection path) still pass — full session.test.ts is green (32/32).

I have read the CLA Document and I hereby sign the CLA

`loadSession()` always loaded the most recently modified session file and
ignored the session the user picked in the `cn ls` TUI. The `ls` command
already communicates the selection by setting `CONTINUE_CLI_TEST_SESSION_ID`
(the same env var `SessionManager` uses to pin the current session id), but
`loadSession()` never consulted it, so `--resume` always reopened the latest
session.

Honor that env var first when set, falling back to the most-recent session
when it is absent or the id can't be loaded. Plain `cn --resume` behavior is
unchanged.

Fixes continuedev#12927

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Purv-Kabaria Purv-Kabaria requested a review from a team as a code owner July 10, 2026 16:00
@Purv-Kabaria Purv-Kabaria requested review from sestinj and removed request for a team July 10, 2026 16:00
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 10, 2026
@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@Purv-Kabaria

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

Empty commit to retrigger CI after infra hangs/flakes on the previous
run (macOS test-matrix job hung, JetBrains Autocomplete test fails
identically on main, Windows VSIX post-build cleanup was cancelled).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cn ls always resumes the latest session regardless of user selection

1 participant